package projectEuler.net;

public class Problem_045 {
	private static boolean isPentagonNumber(long Pn){
		double tmp = (Math.sqrt(24*Pn+1)+1)/6;
		return (tmp==(int)tmp);
	}
	private static boolean isHexagonNumber(long Hx){
		double tmp = (Math.sqrt(8*Hx+1)+1)/4;
		return (tmp == (int)tmp);
	}
	private static long buildTriangleNumber(int n){
		return (long)n*(n+1)/2;
	}
	public static long findTriPenHexNum(){
		int i = 285;
		long tmp;
		while(true){
			i++;
			tmp = buildTriangleNumber(i);
//			System.out.printf("__%d\n", tmp);
			if(isPentagonNumber(tmp) && isHexagonNumber(tmp))
				return tmp;
		}
	}
}
